package com.fiona.common.base.config;

import java.net.InetSocketAddress;
import java.util.Properties;

import com.fiona.core.util.PropertiesFileUtil;

import cn.hutool.core.net.NetUtil;

/**
 * 配置信息
 */
public class FionaConfig {

	private static Properties properties = null;
	private static String configPath = "fiona.properties";
	private static InetSocketAddress socketAddress;

	
	/**
	 * 加载配置文件
	 * @param fionaConfig 后缀
	 * @throws IllegalArgumentException 
	 */
	public static void loadConfig() throws IllegalArgumentException {
		properties = PropertiesFileUtil.readPropertiesFile(configPath);
		if (null != properties && properties.containsKey("rpc.port")) {
			if (!properties.containsKey("rpc.registry.group")) {
				throw new IllegalArgumentException();
			}
			socketAddress = InetSocketAddress.createUnresolved(NetUtil.LOCAL_IP, Integer.parseInt(properties.getProperty("rpc.port")));
			RpcConfig.putConfig(properties);
		}
	}


	/**
	 * 获取配置信息
	 * @return json
	 */
	public static Properties getConfig() {
		return properties;
	}
	
	public static InetSocketAddress getServerAddress() {
		return socketAddress;
	}
}
